The present invention relates generally to an improved data processing system and, in particular, to a process and system for improved execution performance in a Java virtual machine.
Since Java is an interpreted language, any programs written in Java, after being converted into Java class files, are interpreted by a Java virtual machine (JVM). In order to improve performance, many JVMs may compile Java classes into platform-specific binary code after they are loaded into the JVM. Then, instead of being interpreted, Java classes are executed in their compiled native code format, similar to programs written in other languages, such as C, C++, etc. Such just-in-time (JIT) compilation of Java programs can significantly improve the speed of execution of Java programs.
A high performance JIT compiler is the key to a high performance Java implementation, and one of the most important actions of a high performance JIT compiler is optimizing method invocation. Because Java is an object-oriented language, methods and method invocation are prevalent in typical Java programs. In Java, there are three kinds of method invocations: (1) static method invocation, also known as class method invocation; (2) interface method invocation; and (3) instance method invocation. An instance invocation can be a non-virtual method invocation (only for private methods and object instance initialization methods) or a virtual method invocation. While static method invocations and non-virtual instance method invocations are easier to optimize due to their static nature, interface method invocations and virtual instance method invocations are the most prevalent in Java. Therefore, improving virtual and interface method invocation is very important for the overall performance of a JIT compiler.
In Java, a virtual method can be declared final. A final method can not be overridden by any subclass, which prevents malicious modification of trusted and verified code and ensures consistency. Hence, invocations of final methods can be more easily optimized by the JIT compiler than those of regular virtual methods.
An important technique of method invocation optimization is called inlining. A method is inlined if its code is compiled into the calling method""s context. Both static and non-virtual methods can be inlined. Final virtual methods, typically though not always, can be inlined. However, a disadvantage is that regular virtual methods cannot be directly inlined.
Inlining has important benefits. It dramatically reduces the frequency of method invocations, which saves the time needed to perform those method invocations. More importantly, inlining is synergistic with other code optimizations because it makes those optimizations more effective. Inlining produces much larger blocks of code for the optimizer to work on. This provides a situation that significantly increases the effectiveness of traditional compiler optimizations, thus overcoming a major obstacle to increased Java programming language performance.
Therefore, in order to improve the performance of certain Java programs, it would be advantageous to provide a JIT compiler with the ability to improve the performance of a program by improving the manner in which its methods are invoked. It would be particularly advantageous to provide a consistent process by which the invocation of virtual methods may be optimized.
The present invention provides a process and system for optimizing an invocation of a method. A determination is made to compile a calling method, and a call to a callee method is detected within the first method. The callee method may be a non-final, virtual method, and a determination may be made that the callee method has not been previously overridden. The callee method is then inlined within the first method. In addition, no conditional statements are inserted into the calling method along with the inlined method. The determination to compile and optimize these methods may be made by a just-in-time compiler, and if the methods are Java methods, then a Java just-in-time compiler performs the optimization process. If a determination is made to load a class that contains a method that overrides the callee method, then the calling method is recompiled or patched.